package com.v1.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.v1.lo.BaseLO;
import com.v1.lo.CommentTran;
import com.v1.lo.Statement;
import com.v1.model.Comment;
import com.v1.model.Wish;

public class ItemAction extends DefaultAction {

	public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return INDEX;
	}

	public ActionForward comment(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer itemid = getInteger(request, "itemid");
		String visitor = getString(request, "visitor");
		String comment = getString(request, "comment");
		Comment model = new Comment();
		model.setComment(comment);
		model.setVisitor(visitor);
		model.setItemid(itemid);

		Integer categoryid = getInteger(request, "categoryid");
		String contact = getString(request, "contact");
		if (StringUtils.isNotEmpty(contact)) {
			Wish wish = new Wish();
			wish.setContact(contact);
			wish.setCategoryid(categoryid);
			CommentTran lo = (CommentTran) getBean("CommentTran");
			lo.addCommentTran(model, wish);
		} else {
			BaseLO lo = (BaseLO) getBean("BaseLO");
			lo.insert(model, Statement.Comment_addComment);
		}

		ActionForward copy = statusForward(mapping, "item", categoryid, itemid);
		return copy;
	}

}